package
{
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.events.Event;
	import ui.Button;
	
	public class ProgressBar extends Sprite
	{
		private		var	_percentDownload:Number = 0.0;
		private		var _downloadPic:Bitmap = null;
		
		private		var _percentPlay:Number = 0.0;
		private		var _playPic:Button = null;
		
		public function ProgressBar()
		{
			super();
			
			var sliderBg:Bitmap = Asset.getSliderBgImg();
			this.addChild(sliderBg);
			
			this._downloadPic = Asset.getSliderPreImg1();			
			this.addChild(this._downloadPic);
			this._downloadPic.width = 0;
			
			this._playPic = new Button(1,3,Asset.getSliderPreImg2());
			this.addChild(this._playPic);
			this._playPic.width = 0;
			
			this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
		}
		
		public	function	onEnterFrame(evt:Event):void{
			var progress:Number = this.width * this._percentDownload;
			this._downloadPic.width = progress;	
			progress = this.width * this._percentPlay;
			this._playPic.width = progress;
		}
		
		public	function set percentDownload(percent:Number):void{
			if (percent > 1.0){
				this._percentDownload = 1.0;
				return;
			}
			
			if (percent < 0.0){
				this._percentDownload = 0.0;
				return;
			}
			
			this._percentDownload = percent;
		}
		
		public	function	get percentDownload():Number{
			return this._percentDownload;
		}
		
		public	function	set	percentPlay(percent:Number):void{
			if (percent > 1.0){
				this._percentPlay = 1.0;
				return;
			}
			
			if (percent < 0.0){
				this._percentPlay = 0.0;
				return;
			}
			
			this._percentPlay = percent;
		}
		
		public	function	get percentPlay():Number{
			return this._percentPlay;
		}
		
	}
}